<template>
  <div class="content">
    <van-sticky>
      <van-nav-bar
        @click-left="$router.back()"
        left-arrow
        title="输入支付密码"
      ></van-nav-bar>
    </van-sticky>
    <div class="main">
      <div class="main-item">
        <span>请输入支付密码</span>
      </div>
      <div class="passwords">
        <van-password-input
          :value="value"
          :gutter="10"
          :focused="showKeyboard"
          @focus="showKeyboard = true"
        />
        <van-number-keyboard
          v-model="value"
          :show="showKeyboard"
          @input="onInput"
          @delete="onDelete"
          @blur="showKeyboard = false"
        />
      </div>
      <div class="main-items">
        <p>为了保障您的财产安全，请不要设置与常用支付软件相同密码</p>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      value: "",
      showKeyboard: true,
    };
  },
  created() {
    document.querySelector("#app").style.width = "100%";
    document.querySelector("#app").style.height = "100vh";
    document.querySelector("#app").style.backgroundColor = "#f3f5f7";
  },
  methods: {
    onInput(key) {
      this.value = (this.value + key).slice(0, 6);
      if (this.value.length == 6) {
        this.$api
          .cancelDankCard({
            paymentCode: this.value,
            customerId: this.$store.state.userInfo.id,
          })
          .then((res) => {
            if (res.code == 0) {
              this.$toast("解绑成功");
              this.$router.push("/personal");
            }
          });
      }
    },
    onDelete() {
      this.value = this.value.slice(0, this.value.length - 1);
    },
  },
};
</script>
<style lang="less" scoped>
.main {
  width: 100%;
  height: 100vh;
  text-align: center;
  line-height: 60px;
  .main-item {
    span {
      font-size: 12px;
      color: #999;
    }
  }
  .main-items {
    font-size: 11px;
    color: #999;
  }
}
</style>